package com.sk.waste.app.views

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import com.lc.smc.lib.bases.LCObject
import com.lc.smc.lib.interfaces.LCInterface.LcOnPnButtonClickLitener
import com.sk.waste.app.R

/**
 *  @time 2025/4/29  17:13
 *  @desc 提醒
 */
class SkAlertDialog(context: Context?) : LCObject() {
    private val mDialog: Dialog?
    private val tTextView: TextView
    private val mTextView: TextView
    private val bttCancle: Button
    private val bttConfirm: Button
    private val rootView: LinearLayout
    var buttonOnClickListener: LcOnPnButtonClickLitener? = null

    init {
        mDialog = Dialog(context!!, R.style.lc_style_dialog)
        val inflater = LayoutInflater.from(context)
        val view = inflater.inflate(R.layout.view_skalert_dialog, null)
        tTextView = view.findViewById<View>(R.id.dialog_title) as TextView
        mTextView = view.findViewById<View>(R.id.dialog_textview) as TextView
        bttCancle = view.findViewById<View>(R.id.dialog_cancle) as Button
        bttConfirm = view.findViewById<View>(R.id.dialog_confirm) as Button
        rootView = view.findViewById<View>(R.id.dialog_root_view) as LinearLayout
        bttCancle.setOnClickListener {
            cancel()
            if (buttonOnClickListener != null)
                buttonOnClickListener!!.onNegetiveClick()
        }
        bttConfirm.setOnClickListener {
            cancel()
            if (buttonOnClickListener != null)
                buttonOnClickListener!!.onPositiveClick(mTextView.text.toString())
        }
        mDialog.setCancelable(false)
        mDialog.setContentView(view)
    }

    /**
     * 仅提醒
     */
    fun show(msg: String) {
        bttCancle.visibility = View.GONE
        bttConfirm.text = msg
        mDialog?.show()
    }

    /**
     * 仅提醒
     */
    fun show() {
        bttCancle.visibility = View.GONE
        mDialog?.show()
    }

    /**
     * 提醒+取消、确定
     */
    fun showExpend() {
        bttCancle.visibility = View.VISIBLE
        mDialog?.show()
    }

    fun setContentCenter(isCenter: Boolean) {
        if (isCenter)
            mTextView.gravity = Gravity.CENTER
        else
            mTextView.gravity = Gravity.LEFT
    }

    fun cancel() {
        mDialog!!.cancel()
    }

    fun setTitleAndContent(titleStr: String, textStr: String) {
        tTextView.text = titleStr
        mTextView.text = textStr
    }

    fun setOnclickListener(onclick: LcOnPnButtonClickLitener) {
        buttonOnClickListener = onclick
    }
}